package com.colin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.colin.pojo.Guest;
import com.colin.pojo.GuestList;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface GuestMapper extends BaseMapper<Guest> {
    @Select({
            "<script>" ,
            "select a.id,a.content,u.user as username,a.create_time from guest as a inner join users as u on u.id = a.uid" ,
            "<where>",
            "<if test='uid != null'>a.uid = #{uid}</if>" ,
            "<if test='content != null'>and a.content like #{content}</if>" ,
            "</where>" ,
            "</script>"
    })
    List<GuestList> queryAllGuest(Map map);

    /**
     * 查询单条记录根据ID
     * @param id 数据ID
     * @return 查询信息
     */
    @Select("select a.id,a.content,u.user as username,a.create_time from guest as a inner join users as u on u.id = a.uid where a.id = #{id}")
    GuestList queryGuestById(Integer id);
}
